package com.tianruan.dc.modules.sys.user.service.impl;

import com.tianruan.dc.common.utils.IdGen;
import com.tianruan.dc.modules.sys.user.entity.dto.ConsultationDTO;
import com.tianruan.dc.modules.sys.user.entity.dto.TutorSolutionDTO;
import com.tianruan.dc.modules.sys.user.mapper.TutorSolutionMapper;
import com.tianruan.dc.modules.sys.user.service.ITutorSolutionService;
import com.tianruan.dc.modules.sys.user.utils.UserUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j

public class TutorSolutionServiceImpl implements ITutorSolutionService {

    @Autowired
    private TutorSolutionMapper tutorSolutionMapper;

    /**
     * 新增解答
     * @param tutorSolutionDTO
     */
    @Override
    public void add(TutorSolutionDTO tutorSolutionDTO, String id){
        tutorSolutionDTO.setId(IdGen.uuid());
        tutorSolutionDTO.setConsultation_id(id);
        tutorSolutionDTO.setCreateBy(UserUtils.getUser().getName());
        tutorSolutionDTO.setCreateDate(LocalDateTime.now());
        tutorSolutionDTO.setUpdateDate(LocalDateTime.now());
        tutorSolutionDTO.setDelFlag(String.valueOf(0));
        tutorSolutionMapper.insert(tutorSolutionDTO);
    }

    /**
     * 删除解答
     * @param tutorSolutionDTO
     */
    @Override
    public void delete(TutorSolutionDTO tutorSolutionDTO) {
        tutorSolutionDTO.setDelFlag(String.valueOf(1));
        tutorSolutionMapper.delete(tutorSolutionDTO);
    }

    /**
     * 根据id查询解答
     * @param id
     * @return
     */
    @Override
    public TutorSolutionDTO getbyid(String id) {
        return tutorSolutionMapper.getbyid(id);
    }

    /**
     * 修改解答
     * @param tutorSolutionDTO
     */
    @Override
    public void update(TutorSolutionDTO tutorSolutionDTO) {
        tutorSolutionDTO.setUpdateDate(LocalDateTime.now());
        tutorSolutionMapper.update(tutorSolutionDTO);
    }

    /**
     *根据咨询id查询该咨询下所有解答
     * @param id
     * @return
     */
    @Override
    public List<ConsultationDTO> selectSolution(String id) {
        return tutorSolutionMapper.selectSolution(id);
    }

}
